﻿using Ln.Fram.SqlSugarCore.Abstractions;
using Ln.Rbac.Domain.Entities;
using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Guids;

namespace Ln.Rbac.SqlSugarCore.DataSeeds;

public class DeptDataSeed : IDataSeedContributor, ITransientDependency
{
	#region 构造函数
	public DeptDataSeed(ISqlSugarRepository<DeptAggregateRoot> repository, IGuidGenerator guidGenerator) => (_repository, _guidGenerator) = (repository, guidGenerator);
	#endregion

	#region 成员属性
	private ISqlSugarRepository<DeptAggregateRoot> _repository;
	private IGuidGenerator _guidGenerator;
	#endregion

	#region 自身方法
	public async Task SeedAsync(DataSeedContext context)
	{
		if (!await _repository.IsAnyAsync(x => true)) await _repository.InsertManyAsync(GetSeedData());
	}

	private List<DeptAggregateRoot> GetSeedData()
	{
		var entities = new List<DeptAggregateRoot>();
		entities.AddRange([
			new DeptAggregateRoot(_guidGenerator.Create()){ DeptName = "路维光电", DeptCode = "00", OrderNum = 100, IsDeleted = false, Leader = "杜武兵" },
			new DeptAggregateRoot(_guidGenerator.Create()){ DeptName = "深圳路维", DeptCode = "10", OrderNum = 110, IsDeleted = false, Leader = "杜武兵" },
			new DeptAggregateRoot(_guidGenerator.Create()){ DeptName = "成都路维", DeptCode = "20", OrderNum = 120, IsDeleted = false, Leader = "杜武兵" },
			new DeptAggregateRoot(_guidGenerator.Create()){ DeptName = "成都科技", DeptCode = "30", OrderNum = 130, IsDeleted = false, Leader = "杜武兵" },
		]);
		return entities;
	}
	#endregion
}
